package com.AX.mapper;

import com.AX.DTO.ParkingLotInfo;
import com.AX.entity.ParkingLot;
import org.apache.ibatis.annotations.*;

import java.util.List;

//停车场信息
@Mapper
public interface ParkingLotMapper {
    // 获取所有停车场基本信息
    @Select("SELECT parking_lot_id, name, total_spaces ,ST_AsText(coordinate) AS coordinate FROM parking_lots")
    @Results({
            @Result(property = "parkingLotId", column = "parking_lot_id"),
            @Result(property = "totalSpaces", column = "total_spaces"),
            @Result(property = "coordinate", column="coordinate" ,typeHandler=com.AX.handler.GeoPointTypeHandler.class)
    })
    List<ParkingLot> findAll();

    // 统计可用车位数量
    @Select("SELECT COUNT(*) FROM parking_spaces " +
            "WHERE parking_lot_id = #{parkingLotId} AND status = 'AVAILABLE'")
    int countAvailableSpaces(@Param("parkingLotId") Integer parkingLotId);

    @Select("SELECT parking_lot_id, name, total_spaces, ST_AsText(coordinate) AS coordinate " +
            "FROM parking_lots " +
            "WHERE parking_lot_id = #{parkingLotId}")
    @Results({
            @Result(property = "parkingLotId", column = "parking_lot_id"),
            @Result(property = "totalSpaces", column = "total_spaces"),
            @Result(property = "coordinate", column="coordinate" ,typeHandler=com.AX.handler.GeoPointTypeHandler.class)
    })
    ParkingLot find(Integer parkingLotId);
}
